#ifndef GHOST_H
#define GHOST_H

/*
    This header defines two 'Model' classes relating to ghosts:
        Ghost        - contains the cooresponding ghost information
        GhostManager - The ghost card holder for the whole game

        All ghost object should belong to one ghost manager
*/

#include <QObject>
#include "gs.h"

using namespace gs;

namespace gs
{
class Ghost : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString imagePath READ getImagePath CONSTANT)
    Q_PROPERTY(QString ghostName READ getName  CONSTANT)
    Q_PROPERTY(int ghostID  READ getID CONSTANT)
    Q_PROPERTY(int resist0  READ getResist0 CONSTANT)
    Q_PROPERTY(int resist1  READ getResist1 CONSTANT)
    Q_PROPERTY(int resist2  READ getResist2 CONSTANT)
    Q_PROPERTY(int resist3  READ getResist3 CONSTANT)
    Q_PROPERTY(int resist4  READ getResist4 CONSTANT)
    Q_PROPERTY(bool boss    READ isBoss CONSTANT)
    Q_PROPERTY(bool movable READ movable CONSTANT)
    Q_PROPERTY(bool buddha  READ killWithBuddha CONSTANT)
    Q_PROPERTY(GSColor color READ getColor CONSTANT)
    Q_PROPERTY(GhostSkills  skill_l READ getSkillL CONSTANT)
    Q_PROPERTY(GhostSkills  skill_m READ getSkillM CONSTANT)
    Q_PROPERTY(GhostSkills  skill_r READ getSkillR CONSTANT)
public slots:
    void exocise();
public:

    static QString ColorToString ( GSColor c );
    static Qt::GlobalColor ColorToQColor ( GSColor c );
    static QString SkillsToString ( GhostSkills s );

    Ghost( GhostManager * parent, // a ghost manager object
           QString path,
           QString name,
           int id,
           GSColor  color,
           GhostSkills  skill_l,
           GhostSkills  skill_m,
           GhostSkills  skill_r,
           int resist0  = 0,
           int resist1  = 0,
           int resist2  = 0,
           int resist3  = 0,
           int resist4  = 0,
           bool boss    = false,
           bool buddha  = false
           );

    int            getID           () { return _ghostid; }
    int            getResist0      () { return _resist0; }//red
    int            getResist1      () { return _resist1; }//yellow
    int            getResist2      () { return _resist2; }//blue
    int            getResist3      () { return _resist3; }//green
    int            getResist4      () { return _resist4; }//black
    GhostSkills    getSkillL       () { return _skill_l; }
    GhostSkills    getSkillM       () { return _skill_m; }
    GhostSkills    getSkillR       () { return _skill_r; }
    GSColor        getColor        () { return _color; }
    GhostBoard *   getGhostBoard   () { return _ghostboard; }
    bool           isBoss          () { return _boss; }
    bool           killWithBuddha  () { return _buddha; }
    QString        getName         () { return _ghostname; }
    QString        getImagePath    () { return _imgpath; }
    bool           movable         () { return _skill_m.testFlag( HAUNTER ); }
    GhostSkillList * getSkillObjectL () { return _skill_obj_l; }
    GhostSkillList * getSkillObjectM () { return _skill_obj_m; }
    GhostSkillList * getSkillObjectR () { return _skill_obj_r; }
    void           setGhostBoard(GhostBoard * b) { _ghostboard = b; }
private:
    QString       _imgpath;
    QString       _ghostname;
    int           _ghostid;
    GSColor       _color;
    GhostSkills   _skill_l;
    GhostSkills   _skill_m;
    GhostSkills   _skill_r;
    int           _resist0;
    int           _resist1;
    int           _resist2;
    int           _resist3;
    int           _resist4;
    bool          _movable;
    bool          _boss;
    bool          _buddha;
    GhostSkillList * _skill_obj_l;
    GhostSkillList * _skill_obj_m;
    GhostSkillList * _skill_obj_r;
    GhostBoard *  _ghostboard;
};


/****
  The GhostManager is the entry for the game. It is designed
  as a singleton type, i.e., user should fetch the object by
  calling GetManager() function, once if CreateManager is called.
****/
class GhostManager : public QObject
{
    Q_OBJECT
public:
    void add( Ghost* ghost );
    GameTable * getTable() { return _table; }
    QList <Ghost*> getList( int rounds = 2, int trash = 3, bool shuffle = false );
    static void CreateManager( GameTable * );
    static GhostManager * GetManager();
    static Ghost* DefaultGhost();
private:
    int _ghostcount;
    GameTable * _table;
    GhostManager( GameTable *, QObject* parent = 0 );
    static GhostManager * _ghostmanager;
    QList <Ghost*> _tglist; // trash ghosts list
    QList <Ghost*> _bglist; // boss ghosts list
};

}
#endif // GHOST_H
